<template>
	<div>
		<div class="record_date">
			<el-row>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">总用户数</div>
							<div class="text_color"><span>{{tableData.allCount ? tableData.allCount : 0}}</span>人</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">今日新增</div>
							<div class="text_color"><span>{{tableData.dayAddUser ? tableData.dayAddUser : 0}}</span>人</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">本月新增</div>
							<div class="text_color"><span>{{tableData.monthAddUser ? tableData.monthAddUser : 0}}</span>人</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">本年新增</div>
							<div class="text_color"><span>{{tableData.yearAddUser ? tableData.yearAddUser : 0}}</span>人</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">今日接单数量 </div>
							<div class="text_color"><span>{{tableData.indentCount ? tableData.indentCount : 0}}</span>单</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">今日收入</div>
							<div class="text_color"><span>{{tableData.dayIncome ? tableData.dayIncome : 0 }}</span>元</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">本月收入 </div>
							<div class="text_color"><span>{{tableData.monthIncome ? tableData.monthIncome : 0}}</span>元</div>
						</div>
					</div>
				</el-col>
				<el-col :span="6" class="cards">
					<div class="box">
						<div class="box_num">
							<div class="box_color">本年收入</div>
							<div class="text_color"><span>{{tableData.yearIncome ? tableData.yearIncome : 0}}</span>元</div>
						</div>
					</div>
				</el-col>
			</el-row>
			<div>
				<el-select v-model="flag" style="width:150px;margin-left: 10px;" @change="orderfenxi">
					<el-option v-for="item in flags" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>&nbsp;&nbsp;&nbsp;
				<el-date-picker style="width: 200px;margin-left: 10px;" v-model="info.stockDate" align="right"
					type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择开始时间"
					@change="animeOrder">
				</el-date-picker>
			</div>
			<el-tabs v-model="activeName" @tab-click="handleClick" style="margin-left: 10px;">
				<el-tab-pane label="用户分析" name="first">
					<el-row>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">累计用户</div>
									<div class="text_color">
										<span>{{usersStat.allUser ? usersStat.allUser : 0}}</span>人</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">师傅用户</div>
									<div class="text_color">
										<span>{{usersStat.userCount1 ? usersStat.userCount1 : 0}}</span>人</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">普通用户</div>
									<div class="text_color">
										<span>{{usersStat.userCount2 ? usersStat.userCount2 : 0}}</span>人</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">手机号用户</div>
									<div class="text_color">
										<span>{{usersStat.phoneUserCount ? usersStat.phoneUserCount : 0}}</span>人</div>
								</div>
							</div>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="订单分析" name="dingdan">
					<el-row>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">累计订单</div>
									<div class="text_color">
										<span>{{orderStat.allCount ? orderStat.allCount : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">待支付订单</div>
									<div class="text_color">
										<span>{{orderStat.daiZhiFu ? orderStat.daiZhiFu : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">待接单订单</div>
									<div class="text_color">
										<span>{{orderStat.daiJieDan ? orderStat.daiJieDan : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">已接单订单</div>
									<div class="text_color">
										<span>{{orderStat.yiJieiDan ? orderStat.yiJieiDan : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">进行中订单</div>
									<div class="text_color">
										<span>{{orderStat.jinXingZhong ? orderStat.jinXingZhong : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">已完成订单</div>
									<div class="text_color">
										<span>{{orderStat.yiWanChen ? orderStat.yiWanChen : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">已取消订单</div>
									<div class="text_color">
										<span>{{orderStat.yiQuXiao ? orderStat.yiQuXiao : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="任务分析" name="renwu">
					<el-row>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">发单总金额</div>
									<div class="text_color">
										<span>{{taskStat.billMoney ? taskStat.billMoney : 0}}</span>元</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">接单总金额</div>
									<div class="text_color">
										<span>{{taskStat.receivingMoney ? taskStat.receivingMoney : 0}}</span>元</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">发单数量</div>
									<div class="text_color">
										<span>{{taskStat.billCount ? taskStat.billCount : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
						<el-col :span="6" class="cards">
							<div class="box">
								<div class="box_num">
									<div class="box_color">接单数量</div>
									<div class="text_color">
										<span>{{taskStat.reveivingCount ? taskStat.reveivingCount : 0}}</span>笔</div>
								</div>
							</div>
						</el-col>
					</el-row>
				</el-tab-pane>
        <el-tab-pane label="平台收入统计" name="pingtai">
        	<el-row>
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">总收入</div>
        					<div class="text_color">
        						<span>{{platformData.allMoneySum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">服务费收入</div>
        					<div class="text_color">
        						<span>{{platformData.serviceSum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<!-- <el-col :span="6" class="cards">
              <div class="box">
                <div class="box_num">
                  <div class="box_color">保价费收入</div>
                  <div class="text_color">
                    <span>{{platformData.cargoInsurance}}</span>元
                  </div>
                </div>
              </div>
            </el-col> -->
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">师傅保证金收入</div>
        					<div class="text_color">
        						<span>{{platformData.cashDepositMoney}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">扣除师傅保证金收入</div>
        					<div class="text_color">
        						<span>{{platformData.deductMoneySum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<!-- </el-row>
          <el-row> -->
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">即时代驾收入</div>
        					<div class="text_color">
        						<span>{{platformData.firstMoneySum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">朋友代叫收入</div>
        					<div class="text_color">
        						<span>{{platformData.secondMoneySum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        		<el-col :span="6" class="cards">
        			<div class="box">
        				<div class="box_num">
        					<div class="box_color">预约代驾收入</div>
        					<div class="text_color">
        						<span>{{platformData.thirdMoneySum}}</span>元
        					</div>
        				</div>
        			</div>
        		</el-col>
        	</el-row>
        </el-tab-pane>
        <el-tab-pane label="待审核统计" name="daishenhe">
          <el-row>
            <el-col :span="6" class="cards">
              <div class="box">
                <div class="box_num">
                  <div class="box_color">待提现审核</div>
                  <div class="text_color"><span style="color: red;cursor: pointer;"
                      @click="btnDsh(1)">{{numberDtx ? numberDtx : 0 }}</span>个</div>
                </div>
              </div>
            </el-col>
            <el-col :span="6" class="cards">
              <div class="box">
                <div class="box_num">
                  <div class="box_color">认证待审核</div>
                  <div class="text_color"><span style="color: red;cursor: pointer;"
                      @click="btnDsh(2)">{{numberDrz ? numberDrz : 0}}</span>个</div>
                </div>
              </div>
            </el-col>
            <el-col :span="6" class="cards">
              <div class="box">
                <div class="box_num">
                  <div class="box_color">投诉待审核</div>
                  <div class="text_color"><span style="color: red;cursor: pointer;"
                      @click="btnDsh(3)">{{numberDts ? numberDts : 0}}</span>个</div>
                </div>
              </div>
            </el-col>
            <el-col :span="6" class="cards">
              <div class="box">
                <div class="box_num">
                  <div class="box_color">推广申请待审核</div>
                  <div class="text_color"><span style="color: red;cursor: pointer;"
                      @click="btnDsh(4)">{{numberDtg ? numberDtg : 0 }}</span>个</div>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-tab-pane>
				<!-- <el-tab-pane label="任务收入分析" name="fourth">
					<el-table v-loading="tableDataLoading" :data="tableData2.list">
						<el-table-column prop="shipUserName" label="派单人姓名">
							<template slot-scope="scope">
								<span style="color: #4f9dec;cursor: pointer;"
									@click="updates1(scope.row.userId)">{{scope.row.nickName ? scope.row.nickName : 'null'}}</span>
							</template>
						</el-table-column>
						<el-table-column prop="nickName2" label="接单人姓名">
							<template slot-scope="scope">
								<span style="color: #4f9dec;cursor: pointer;"
									@click="updates1(scope.row.riderUserId)">{{scope.row.riderNickName ? scope.row.riderNickName : 'null'}}</span>
							</template>
						</el-table-column>
						<el-table-column prop="platformMoney" label="平台收入">
						</el-table-column>
						<el-table-column prop="createTime" label="创建时间">
						</el-table-column>
					</el-table>
					<div style="text-align: center;margin-top: 10px;float:right">
						<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:page-sizes="[5, 10, 15, 20]" :page-size="limit" :current-page="page"
							layout="total,sizes, prev, pager, next,jumper" :total="tableData2.totalCount">
						</el-pagination>
					</div>
				</el-tab-pane> -->
			</el-tabs>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				limit: 5,
				page: 1,
				tableData: {},
				tableData2: {},
				colonelData: [],
				commodityData: [],
				userjfData: [],
				incomeData: [],
				activeName: 'first',
				tableDataLoading: true,
				flag: 'day',
				usersumData: {},
				taskStat: {},
				usersStat:{},
				orderStat:{},
				data: '',
				time: '',
				platform: '',
				type: '',
				balance: -1,
				// flag: 1,
				info: {
					stockDate: this.getNowTime(), //日期
				},
				flags: [{
					value: 'day',
					label: '按天查询'
				}, {
					value: 'month',
					label: '按月查询'
				}, {
					value: 'year',
					label: '按年查询'
				}],
        platformData: {},
        numberDtx:0,
        numberDrz:0,
        numberDts:0,
        numberDtg:0,
			}
		},
		mounted() {
			// this.colonel()
			this.usersData()

			this.taskData()
			this._getData() //用户统计
			// this.incomeSelect() //收入
		},
		methods: {
			// 详情跳转
			updates(row) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: row.userId
					}
				})
			},
			updates1(userId) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: userId
					}
				})
			},
			updates2(row) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: row.userId2
					}
				})
			},
			handleSizeChange(val) {
				this.limit = val;
				this.taskData();
			},
			handleCurrentChange(val) {
				this.page = val;
				this.taskData();
			},
			// 用户分析选择日期
			animeDat() {
				this._getData()
			},
			// 订单分析选择日期
			animeOrder() {
				console.log('info',this.info)
				this.taskData()
				this.usersData()
				this.orderData()
        this.platformSelect()
        setInterval(() => {
          if (this.$cookie.get('numberDtx')) {
          	this.numberDtx = this.$cookie.get('numberDtx')
          }
          if (this.$cookie.get('numberDrz')) {
          	this.numberDrz = this.$cookie.get('numberDrz')
          }
          if (this.$cookie.get('numberDts')||this.$cookie.get('numberDss')) {
          	this.numberDts = Number(this.$cookie.get('numberDts')) + Number(this.$cookie.get('numberDss'))
          }
          if (this.$cookie.get('numberDtg')) {
          	this.numberDtg = this.$cookie.get('numberDtg')
           }
        }, 1000)
				// this.colonel()
			},
			// 订单分析年月日
			orderfenxi(value) {
				this.page = 1
				let vanumber = value
				// if (vanumber === 1) {
					this.flag = value
					this.taskData()
					this.orderData()
					this.usersData()
          this.platformSelect()
					// this.colonel()
				// }
				// if (vanumber === 2) {
				// 	this.flag = 2
				// 	this.taskData()
				// 	this.colonel()
				// }
				// if (vanumber === 3) {
				// 	this.flag = 3
				// 	this.taskData()
				// 	this.colonel()
				// }
			},
			// Tabs点击事件
			handleClick(tab, event) {
				this.page = 1

				if (tab._props.label == '用户分析') {
					this.usersData()

				}
				if (tab._props.label == '订单分析') {
					this.orderData()

				}
				if (tab._props.label == '任务分析') {
					this.taskData()

				}
				if (tab._props.label == '任务收入分析') {
					// this.colonel()
					this.taskData()
				}
        if (tab._props.label == '平台收入统计') {
        	this.platformSelect()
        }
        if(tab._props.label == '待审核统计'){
          if (this.$cookie.get('numberDtx')) {
          	this.numberDtx = this.$cookie.get('numberDtx')
          }
          if (this.$cookie.get('numberDrz')) {
          	this.numberDrz = this.$cookie.get('numberDrz')
          }
          if (this.$cookie.get('numberDts')||this.$cookie.get('numberDss')) {
          	this.numberDts = Number(this.$cookie.get('numberDts')) + Number(this.$cookie.get('numberDss'))
          }
          if (this.$cookie.get('numberDtg')) {
          	this.numberDtg = this.$cookie.get('numberDtg')
           }
        }
			},
			//处理默认选中当前日期
			getNowTime() {
				var now = new Date();
				var year = now.getFullYear(); //得到年份
				var month = now.getMonth(); //得到月份
				var date = now.getDate(); //得到日期
				var hh = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
				var mm = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
				var ss = now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
				month = month + 1;
				month = month.toString().padStart(2, "0");
				date = date.toString().padStart(2, "0");
				var defaultDate = `${year}-${month}-${date}`;
				return defaultDate;
				this.$set(this.info, "stockDate", defaultDate);
			},
			// 用户统计
			_getData() {
				this.$http({
					url: this.$http.adornUrl('adminerrand/findDataCenter'),
					method: 'get',
					params: this.$http.adornParams({})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						let returnData = data.data;
						this.tableData = returnData
					}

				})
			},
			// 收入统计
			incomeSelect() {
				this.$http({
					url: this.$http.adornUrl('statistical/income'),
					method: 'get',
					params: this.$http.adornParams({})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						let returnData = data.data;
						this.incomeData = returnData
					}
				})
			},
			// 用户分析
			usersData(){
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('adminerrand/selectUserStatistics'),
					method: 'get',
					params: this.$http.adornParams({
						'date': this.info.stockDate,
						'dateType': this.flag,
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.usersStat = returnData
				})
			},
			//订单分析
			orderData() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('adminerrand/selectOrderByStatus'),
					method: 'get',
					params: this.$http.adornParams({
						'date': this.info.stockDate,
						'dateType': this.flag
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.orderStat = returnData
				})
			},
			//任务分析
			taskData() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('adminerrand/taskAnalysis'),
					method: 'get',
					params: this.$http.adornParams({
						'date': this.info.stockDate,
						'dateType': this.flag,
						'page':this.page,
						'limit':this.limit
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data;
					this.taskStat = returnData
					this.tableData2 = returnData.taskAnalysisMoney
				})
			},
			// 任务收入分析
			colonel() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('statistical/incomeAnalysis'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'time': this.info.stockDate,
						'flag': this.flag,
					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.tableDataLoading = false
						let returnData = data.data
						this.tableData2 = returnData
					}
				})
			},
      // 平台收入统计
      platformSelect() {
      	if (this.endTime == '') {
      		this.endTime = this.info2.stockDate2
      	}
      	if (this.startTime == '') {
      		this.startTime = this.info.stockDate
      	}
      	this.tableDataLoading = true
      	this.$http({
      		url: this.$http.adornUrl('cash/incomeStatistics'),
      		method: 'get',
      		params: this.$http.adornParams({
      			'date': this.info.stockDate,
      			'dateType': this.flag
      		})
      	}).then(({
      		data
      	}) => {
      		this.tableDataLoading = false
      		let returnData = data.data
      		this.platformData = returnData
      		// this.totalnum2 = returnData.totalCount
      	})
      },
      // 待审核跳转
      btnDsh(index) {
        if (index == 1) {
          this.$router.replace({
            name: 'financeList',
            query: {
              status: 0
            }
          })
        }
        if (index == 2) {
          this.$router.replace({
            name: 'autonym',
            query: {
              status: 0
            }
          })
        }
        if (index == 3) {
          this.$router.replace({
            name: 'business',
            query: {
              status: 5
            }
          })
        }
        if (index == 4) {
          this.$router.replace({
            name: 'recruitList',
            query: {
              status: 1
            }
          })
        }
      },
		}
	}
</script>

<style scoped>
	.box {
		padding: 44px;
		border: 1px solid #eee;
		margin: 15px 10px;
	}

	.box_num {
		font-size: 14px;
		color: #66b1ff;
	}

	.box_num .box_color {
		color: #333;
		font-size: 14px;
		margin-bottom: 15px;
	}

	.box_num div span {
		font-size: 20px;
		margin-left: 5px;
	}

	.text_color {
		color: #4f9dec;
	}

	.text_color span {
		margin-right: 5px;
	}
</style>
